<?php


namespace App\Http\Controllers;

/*use Illuminate\Support\Facades\Http;
use GuzzleHttp\Client;
use GuzzleHttp\Promise;*/


class TestController extends Controller
{

    // http://httpbin.org
    public function index()
    {

        $client = new \Co\Client(SWOOLE_SOCK_TCP);
        $client->set(array(
            'timeout' => 0.5,//总超时，包括连接、发送、接收所有超时
            'connect_timeout' => 1.0,//连接超时，会覆盖第一个总的 timeout
            'write_timeout' => 10.0,//发送超时，会覆盖第一个总的 timeout
            'read_timeout' => 0.5,//接收超时，会覆盖第一个总的 timeout
        ));
        if (!$client->connect('http://httpbin.org', 80, -1, 0)) {
            exit("connect failed. Error: {$client->errCode}\n");
        }
        $client->send("hello world\n");
        echo $client->recv();
        $client->close();


        return $this->json();
    }

    public function detail()
    {
        sleep(3);
        return $this->json(['name' => '李四']);
    }

    public function goods()
    {
        sleep(3);
        return $this->json(['name' => '张三']);
    }

}
